package com.swak.boot.config.vertx;

import java.util.List;

import org.springframework.boot.context.properties.ConfigurationProperties;

import com.swak.Constants;
import com.swak.reactivex.transport.TransportProperties;

import io.netty.handler.logging.LogLevel;
import io.netty.util.ResourceLeakDetector.Level;
import io.vertx.core.VertxOptions;
import io.vertx.core.file.FileSystemOptions;
import io.vertx.core.http.ClientAuth;
import io.vertx.core.http.HttpServerOptions;
import lombok.Getter;
import lombok.Setter;

/**
 * Vertx 的属性配置
 *
 * @author: lifeng
 * @date: 2020/3/29 19:15
 */
@ConfigurationProperties(prefix = Constants.VERTX_SERVER_PREFIX)
@Getter
@Setter
public class VertxProperties extends TransportProperties {

	private String host = null;
	private int port = 8888;
	private int webSocketPort = 8889;

	/**
	 * 配置是否开启：WebSocket， 如果配置了@ImApi则会开启支持
	 * 
	 */
	private boolean enableWebsocket = false;
	private int webSocketHeartbeatMs = 60 * 1000 * 3;

	private Level leakDetectionLevel = Level.DISABLED;
	private boolean threadCache = true;
	private int eventLoopPoolSize = VertxOptions.DEFAULT_EVENT_LOOP_POOL_SIZE;
	private int internalBlockingThreads = 2;
	private int workerPoolSize = 10;
	private long maxEventLoopExecuteTime = VertxOptions.DEFAULT_MAX_EVENT_LOOP_EXECUTE_TIME;
	private long maxWorkerExecuteTime = VertxOptions.DEFAULT_MAX_WORKER_EXECUTE_TIME;
	private int sendTimeout = 5 * 60 * 1000;
	private String uploadDirectory = "file:uploads/";
	private int bodyLimit = -1;
	private boolean deleteUploadedFilesOnEnd = false;

	/**
	 * 权限验证
	 */
	private String keyStorePath;
	private String keyStorePass = "secret";
	private String keyStoreAlgorithm = "HS256";
	private String tokenName = Constants.TOKEN_NAME;
	private Integer tokenExpiresInSeconds = null;

	/**
	 * 开启压缩
	 */
	private boolean compressionSupported;
	private int compressionLevel = -1;

	/**
	 * 设置服务器证书： 设置此属性则关闭 http2
	 */
	private boolean useSsl;

	/**
	 * http2 需要 配置ssl ，服务的 openssl版本在1.0.2+ 以上才支持 Http2， 如果使用了Ssl 则默认开启 http2
	 */
	private boolean useAlpn;
	private List<String> keyPaths;
	private List<String> certPaths;
	private ClientAuth clientAuth = ClientAuth.NONE;

	/**
	 * 文件处理
	 */
	private boolean classPathResolvingEnabled = false; // FileSystemOptions.DEFAULT_CLASS_PATH_RESOLVING_ENABLED;
	private boolean fileCachingEnabled = false; // FileSystemOptions.DEFAULT_FILE_CACHING_ENABLED;
	private String fileCacheDir = FileSystemOptions.DEFAULT_FILE_CACHING_DIR;

	/**
	 * 表单提交
	 */
	private int maxHeaderSize = HttpServerOptions.DEFAULT_MAX_HEADER_SIZE;
	private int maxFormAttributeSize = HttpServerOptions.DEFAULT_MAX_FORM_ATTRIBUTE_SIZE;

	/**
	 * 这些没有用到
	 */
	private LogLevel serverLogLevel = null;
	private boolean metricAble = true;
	private String rootPath = "io.vertx";
	private int sessionTimeout = 20000;
	private int connectTimeout = 3000;
	private int retryInitialSleepTime = 1000;
	private int retryIntervalTimes = 10000;
	private int retryMaxTimes = 5;
}